﻿using System;
using System.Collections.Generic;
using DataCore.Exeptions;

namespace DataCore.DomainObjects
{
    [Serializable]
    public class MetaClass : DomainObject<long>
    {
        private List<Atribute> _atributes;
        private String _name;

        public MetaClass()
        {
            _name = "";
        }

        public MetaClass(String name)
        {
            _name = name;
            _atributes = new List<Atribute>();
        }

        public void Rename(String name)
        {
            _name = name;
        }

        public void AddAtribute(Atribute atribute)
        {
            if(_atributes.Find(x => x.Name == atribute.Name) == null)
                _atributes.Add(atribute);
            else
            {
                //throw new MetaClassDontHeveThisAtributeExeption();
            }
        }

        public List<Atribute> Atributes
        {
            get { return _atributes; }
            set { _atributes = value; }
        }

        public String Name
        {
            get { return _name;}
            set { _name = value; }
        }

        public bool ValidateAtribute(Atribute atribute)
        {
            return _atributes.Contains(atribute);
        }

        public override int GetHashCode()
        {
            int m = 23;
            return String.Concat(m * 17,
                _atributes != null ? _atributes.GetHashCode().ToString() : "0",
                _name != null ? _name.GetHashCode().ToString() : "0").GetHashCode();
        }

        public override void CopyFrom(DomainObject<long> T)
        {
            throw new NotImplementedException();
        }
    }
}
